<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xml:space="default">
	<xsl:import href="xml-to-string.xslt"/>
	<xsl:output method="xml" encoding="utf-8" indent="yes"/>
	<xsl:param name="assemblyDependencyList"></xsl:param>
	<xsl:param name="orchestrationDependencyList"/>
	<xsl:param name="applicationDependencyList"/>
	<xsl:param name="assemblyRootFolder"/>
	<xsl:param name="assemblyBuildList"/>


	<xsl:template match="/">
		<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Undeploy;Deploy">
			<xsl:comment>This project file is regenerated on every build. Any changes made will be lost on the next build</xsl:comment>
			<Import Project="Build.properties" />

			<Import Project="BizTalkTasks.proj"/>

			<ItemGroup>
				<xsl:for-each select="/BizTalkBaseObject/Applications/Application/Assemblies/Assembly/Orchestrations/Orchestration/Ports/OrchestrationPort">
					<xsl:sort select="../../Name"/>
					<xsl:element name="{translate(parent::*/parent::*/Name, ' .', '')}Ports" namespace="http://schemas.microsoft.com/developer/msbuild/2003">
						<xsl:attribute name="Include">empty</xsl:attribute>
						<OrchestrationPortName><xsl:value-of select="Name"/></OrchestrationPortName>
						<ReceivePort><xsl:value-of select="ReceivePortName"/></ReceivePort>
						<SendPort><xsl:value-of select="SendPortName"/></SendPort>
						<SendPortGroup><xsl:value-of select="SendPortGroupName"/></SendPortGroup>
					</xsl:element>
				</xsl:for-each>
			</ItemGroup>

			<Target Name="Deploy" DependsOnTargets="DeployApplications;StartApplications;RestartHosts"></Target>

			<Target Name="Undeploy" DependsOnTargets="Exists;StopApplications;ReconfigureSendPorts;ReconfigureReceivePorts;UndeployApplications"></Target>

			<Target Name="CleanAndDeploy" DependsOnTargets="Clean;DeployApplications;StartApplications"></Target>

			<Target Name="Exists">
				<xsl:call-template name="Exists"></xsl:call-template>
			</Target>

			<Target Name="StartApplications">
				<Message Text="Starting Applications...."/>
				<xsl:call-template name="Applications">
					<xsl:with-param name="action">Start</xsl:with-param>
				</xsl:call-template>
			</Target>

			<Target Name="StopApplications" DependsOnTargets="Exists">
				<Message Text="Stopping Applications...."/>
				<xsl:call-template name="Applications">
					<xsl:with-param name="action">Stop</xsl:with-param>
				</xsl:call-template>
			</Target>

			<Target Name="DeployApplications">
				<Message Text="Deploying Applications...."/>
				<xsl:call-template name="Applications">
					<xsl:with-param name="action">Deploy</xsl:with-param>
				</xsl:call-template>
			</Target>

			<Target Name="UndeployApplications" DependsOnTargets="Exists">
				<Message Text="Undeploying Applications...."/>
				<xsl:call-template name="Applications">
					<xsl:with-param name="action">Undeploy</xsl:with-param>
				</xsl:call-template>
			</Target>
			
			<Target Name="StopOrchestrations" DependsOnTargets="Exists">
				<Message Text="Stopping orchestrations..."/>
				<xsl:call-template name="Orchestrations">
					<xsl:with-param name="action">Undeploy</xsl:with-param>
				</xsl:call-template>
			</Target>

			<Target Name="ReconfigureSendPorts" DependsOnTargets="Exists">
				<Message Text="Setting Send Ports to default properties..."/>
				<xsl:call-template name="SendPort">
					<xsl:with-param name="action">PreUndeploy</xsl:with-param>
				</xsl:call-template>
			</Target>

			<Target Name="ReconfigureReceivePorts" DependsOnTargets="Exists">
				<Message Text="Setting Receive Ports to default properties..."/>
				<xsl:call-template name="ReceivePort">
					<xsl:with-param name="action">PreUndeploy</xsl:with-param>
				</xsl:call-template>
			</Target>

			<Target Name="UndeployAssemblies" DependsOnTargets="Exists;StopOrchestrations;ReconfigureSendPorts;ReconfigureReceivePorts">
				<Message Text="Undeploying assemblies..."/>
				<xsl:call-template name="DeployAssemblies">
					<xsl:with-param name="action">Undeploy</xsl:with-param>
				</xsl:call-template>
			</Target>

			<Target Name="RemoveSendPorts" DependsOnTargets="Exists;StopOrchestrations;ReconfigureSendPorts;ReconfigureReceivePorts;UndeployAssemblies">
				<Message Text="Removing Send ports..."/>
				<xsl:call-template name="SendPort">
					<xsl:with-param name="action">Undeploy</xsl:with-param>
				</xsl:call-template>
			</Target>
			<Target Name="RemoveReceivePorts" DependsOnTargets="Exists;StopOrchestrations;ReconfigureSendPorts;ReconfigureReceivePorts;UndeployAssemblies">
				<Message Text="Removing Receive Ports..."/>
				<xsl:call-template name="ReceivePort">
					<xsl:with-param name="action">Undeploy</xsl:with-param>
				</xsl:call-template>
			</Target>

			<Target Name="DeployAssemblies">
				<Message Text="Deploying assemblies..."/>
				<xsl:call-template name="DeployAssemblies">
					<xsl:with-param name="action">Deploy</xsl:with-param>
				</xsl:call-template>
			</Target>

			<Target Name="CreateSendPorts" DependsOnTargets="DeployAssemblies">
				<Message Text="Creating Send Ports..."/>
				<xsl:call-template name="SendPort">
					<xsl:with-param name="action">Deploy</xsl:with-param>
				</xsl:call-template>
			</Target>

			<Target Name="CreateSendPortGroups" DependsOnTargets="CreateSendPorts">
				<Message Text="Creating Send Port Groups..."/>
				<xsl:call-template name="SendPortGroups">
					<xsl:with-param name="action">Deploy</xsl:with-param>
				</xsl:call-template>
			</Target>

			<Target Name="CreateReceivePorts">
				<Message Text="Create Receive Ports..."/>
				<xsl:call-template name="ReceivePort">
					<xsl:with-param name="action">Deploy</xsl:with-param>
				</xsl:call-template>
			</Target>

			<Target Name="ConfigureSendPorts">
				<Message Text="Configuring Send Ports" />
				<xsl:call-template name="SendPort">
					<xsl:with-param name="action">Configure</xsl:with-param>
				</xsl:call-template>
			</Target>

			<Target Name="ConfigureReceivePorts">
				<Message Text="Configuring Receive Ports" />
				<xsl:call-template name="ReceivePort">
					<xsl:with-param name="action">Configure</xsl:with-param>
				</xsl:call-template>
			</Target>

			<Target Name="StartOrchestrations" DependsOnTargets="ConfigureSendPorts;ConfigureReceivePorts;DeployAssemblies">
				<Message Text="Starting orchestrations..."/>
				<xsl:call-template name="Orchestrations">
					<xsl:with-param name="action">Deploy</xsl:with-param>
				</xsl:call-template>
			</Target>

			<Target Name="RestartHosts" DependsOnTargets="DeployAssemblies">
				<Message Text="Restarting hosts..."/>
				<xsl:call-template name="Hosts"/>
			</Target>
			<Target Name="Clean">
				<BizTalk2004.Clean />
			</Target>
		</Project>
	</xsl:template>

	<!-- Applications -->
	<xsl:template name="Applications">
		<xsl:param name="action"/>
		<xsl:for-each select="$applicationDependencyList/child::*">
			
			<xsl:if test="$action='Undeploy'">
				<xsl:element name="BizTalk2006.Application.Delete" namespace="http://schemas.microsoft.com/developer/msbuild/2003">
					<xsl:attribute name="Condition">@(Application<xsl:value-of select="translate(Name, ' .', '')"/>Exists) == 'true'</xsl:attribute>
					<xsl:attribute name="Application">
						<xsl:value-of select="Name"/>
					</xsl:attribute>
				</xsl:element>
			</xsl:if>
			
			<xsl:if test="$action='Deploy'">
				<xsl:element name="BizTalk2006.Application.Create" namespace="http://schemas.microsoft.com/developer/msbuild/2003">
					<xsl:attribute name="Application">
						<xsl:value-of select="Name"/>
					</xsl:attribute>
					<xsl:attribute name="Description">
						<xsl:value-of select="Description"/>
					</xsl:attribute>
				</xsl:element>
			</xsl:if>
			
			<xsl:if test="$action='Start'">
				<xsl:element name="BizTalk2006.Application.Start" namespace="http://schemas.microsoft.com/developer/msbuild/2003">
					<xsl:attribute name="Application">
						<xsl:value-of select="Name"/>
					</xsl:attribute>
				</xsl:element>
			</xsl:if>
			
			<xsl:if test="$action='Stop'">
				<xsl:element name="BizTalk2006.Application.Stop" namespace="http://schemas.microsoft.com/developer/msbuild/2003">
					<xsl:attribute name="Application">
						<xsl:value-of select="Name"/>
					</xsl:attribute>
				</xsl:element>
			</xsl:if>
		</xsl:for-each>
	</xsl:template>

	<!-- Send Ports-->
	<xsl:template name="SendPort">
		<xsl:param name="action"/>
		<xsl:for-each select="/BizTalkBaseObject/Applications/Application/SendPorts/SendPort">
			<xsl:variable name="receivePipeline" select="ReceivePipeline"/>
			<xsl:variable name="sendPipeline" select="SendPipeline" />

			<xsl:if test="$action='Undeploy'">
				<xsl:element name="BizTalk2006.SendPort.UnEnlist" namespace="http://schemas.microsoft.com/developer/msbuild/2003">
					<xsl:attribute name="Condition" xml:space="preserve">@(SendPort<xsl:value-of select="translate(Name, ' .', '')"/>Exists) == 'true'</xsl:attribute>
					<xsl:attribute name="Name">
						<xsl:value-of select="Name"/>
					</xsl:attribute>
					<xsl:attribute name="Application">
						<xsl:value-of select="parent::*/parent::*/Name"/>
					</xsl:attribute>
				</xsl:element>
				<xsl:element name="BizTalk2006.SendPort.Delete" namespace="http://schemas.microsoft.com/developer/msbuild/2003">
					<xsl:attribute name="Condition" xml:space="preserve">@(SendPort<xsl:value-of select="translate(Name, ' .', '')"/>Exists) == 'true'</xsl:attribute>
					<xsl:attribute name="Name">
						<xsl:value-of select="Name"/>
					</xsl:attribute>
					<xsl:attribute name="Application">
						<xsl:value-of select="parent::*/parent::*/Name"/>
					</xsl:attribute>
				</xsl:element>
				<xsl:element name="Message" namespace="http://schemas.microsoft.com/developer/msbuild/2003">
					<xsl:attribute name="Text" xml:space="preserve">    <xsl:value-of select="Name"/> removed</xsl:attribute>
				</xsl:element>
				<xsl:text>
					
				</xsl:text>
			</xsl:if>
			
			<xsl:if test="$action='Deploy'">
				<xsl:element name="BizTalk2006.SendPort.Create" namespace="http://schemas.microsoft.com/developer/msbuild/2003">
					<xsl:attribute name="Name">
						<xsl:value-of select="./Name"/>
					</xsl:attribute>
					<xsl:attribute name="Application">
						<xsl:value-of select="parent::*/parent::*/Name"/>
					</xsl:attribute>
					<xsl:attribute name="IsDynamic">
						<xsl:value-of select="./Dynamic"/>
					</xsl:attribute>
					<xsl:attribute name="IsTwoWay">
						<xsl:value-of select="TwoWay"/>
					</xsl:attribute>
					<xsl:attribute name="Priority">
						<xsl:value-of select="Priority"/>
					</xsl:attribute>
					<xsl:attribute name="TrackingTypes">
						<xsl:value-of select="translate(TrackingType, ' .', ',')"/>
					</xsl:attribute>
					<xsl:attribute name="Filter">
						<xsl:value-of select="Filter"/>
					</xsl:attribute>
					<xsl:attribute name="InboundMaps">
						<xsl:value-of select="InboundMaps/Transform/AssemblyQualifiedName"/>
					</xsl:attribute>
					<xsl:attribute name="OutboundMaps">
						<xsl:value-of select="OutboundMaps/Transform/AssemblyQualifiedName"/>
					</xsl:attribute>
					<xsl:if test="$sendPipeline!=''">
						<xsl:attribute name="SendPipeline">
							<xsl:value-of select="/BizTalkBaseObject/Pipelines/Pipeline[Name=$sendPipeline]/AssemblyName"/>
						</xsl:attribute>
					</xsl:if>
					<xsl:if test="$receivePipeline!=''">
						<xsl:attribute name="ReceivePipeline">
							<xsl:value-of select="/BizTalkBaseObject/Pipelines/Pipeline[Name=$receivePipeline]/AssemblyName"/>
						</xsl:attribute>
					</xsl:if>
					<xsl:attribute name="PrimaryTransportAddress">
						<xsl:value-of select="PrimaryTransport/Address"/>
					</xsl:attribute>
					<xsl:attribute name="PrimaryTransportName">
						<xsl:value-of select="PrimaryTransport/Type"/>
					</xsl:attribute>
					<xsl:attribute name="PrimaryTransportOrderedDelivery">
						<xsl:value-of select="PrimaryTransport/OrderedDelivery"/>
					</xsl:attribute>
					<xsl:attribute name="PrimaryTransportProtocolName">
						<xsl:value-of select="PrimaryTransport/Type"/>
					</xsl:attribute>
					<xsl:attribute name="PrimaryTransportRetryCount">
						<xsl:value-of select="PrimaryTransport/RetryCount"/>
					</xsl:attribute>
					<xsl:attribute name="PrimaryTransportRetryInterval">
						<xsl:value-of select="PrimaryTransport/RetryInterval"/>
					</xsl:attribute>
					<xsl:attribute name="PrimaryTransportServiceWindowEnabled">
						<xsl:value-of select="PrimaryTransport/ServiceWindow/Enabled"/>
					</xsl:attribute>
					<xsl:attribute name="PrimaryTransportServiceWindowStartTime">
						<xsl:value-of select="PrimaryTransport/ServiceWindow/StartTime"/>
					</xsl:attribute>
					<xsl:attribute name="PrimaryTransportServiceWindowEndTime">
						<xsl:value-of select="PrimaryTransport/ServiceWindow/EndTime"/>
					</xsl:attribute>
					<xsl:if test="PrimaryTransport/DataSpecified='true'">
						<xsl:attribute name="PrimaryTransportTransportData">
							<xsl:value-of select="PrimaryTransport/CustomData"/>
						</xsl:attribute>
					</xsl:if>

					<xsl:if test="SecondaryTransport">
						<xsl:attribute name="SecondaryTransportAddress">
							<xsl:value-of select="SecondaryTransport/Address"/>
						</xsl:attribute>
						<xsl:attribute name="SecondaryTransportName">
							<xsl:value-of select="SecondaryTransport/Type"/>
						</xsl:attribute>
						<xsl:attribute name="SecondaryTransportOrderedDelivery">
							<xsl:value-of select="SecondaryTransport/OrderedDelivery"/>
						</xsl:attribute>
						<xsl:attribute name="SecondaryTransportProtocolName">
							<xsl:value-of select="SecondaryTransport/Type"/>
						</xsl:attribute>
						<xsl:attribute name="SecondaryTransportRetryCount">
							<xsl:value-of select="SecondaryTransport/RetryCount"/>
						</xsl:attribute>
						<xsl:attribute name="SecondaryTransportRetryInterval">
							<xsl:value-of select="SecondaryTransport/RetryInterval"/>
						</xsl:attribute>
						<xsl:attribute name="SecondaryTransportServiceWindowEnabled">
							<xsl:value-of select="SecondaryTransport/ServiceWindow/Enabled"/>
						</xsl:attribute>
						<xsl:attribute name="SecondaryTransportServiceWindowStartTime">
							<xsl:value-of select="SecondaryTransport/ServiceWindow/StartTime"/>
						</xsl:attribute>
						<xsl:attribute name="SecondaryTransportServiceWindowEndTime">
							<xsl:value-of select="SecondaryTransport/ServiceWindow/EndTime"/>
						</xsl:attribute>
						<xsl:if test="SecondaryTransport/DataSpecified='true'">
							<xsl:attribute name="SecondaryTransportTransportData">
								<xsl:value-of select="SecondaryTransport/CustomData"/>
							</xsl:attribute>
						</xsl:if>
					</xsl:if>

					<xsl:attribute name="Server">
						<xsl:value-of select="/BizTalkBaseObject/Server"/>
					</xsl:attribute>
					<xsl:attribute name="Database">
						<xsl:value-of select="/BizTalkBaseObject/MgmtDatabaseName"/>
					</xsl:attribute>
				</xsl:element>
				<xsl:element name="BizTalk2006.SendPort.Start" namespace="http://schemas.microsoft.com/developer/msbuild/2003">
					<xsl:attribute name="Name">
						<xsl:value-of select="./Name"/>
					</xsl:attribute>
					<xsl:attribute name="Application">
						<xsl:value-of select="parent::*/parent::*/Name"/>
					</xsl:attribute>
				</xsl:element>
				<xsl:element name="Message" namespace="http://schemas.microsoft.com/developer/msbuild/2003">
					<xsl:attribute name="Text" xml:space="preserve">    <xsl:value-of select="./Name"/> created and started</xsl:attribute>
				</xsl:element>
				<xsl:text>
					
				</xsl:text>
			</xsl:if>

			<xsl:if test="$action='PreUndeploy'">
				<xsl:element name="BizTalk2006.SendPort.Stop" namespace="http://schemas.microsoft.com/developer/msbuild/2003">
					<xsl:attribute name="Condition" xml:space="preserve">@(SendPort<xsl:value-of select="translate(Name, ' .', '')"/>Exists) == 'true'</xsl:attribute>
					<xsl:attribute name="Name">
						<xsl:value-of select="./Name"/>
					</xsl:attribute>
					<xsl:attribute name="Application">
						<xsl:value-of select="parent::*/parent::*/Name"/>
					</xsl:attribute>
				</xsl:element>
				<xsl:element name="BizTalk2006.SendPort.Configure" namespace="http://schemas.microsoft.com/developer/msbuild/2003">
					<xsl:attribute name="Condition" xml:space="preserve">@(SendPort<xsl:value-of select="translate(Name, ' .', '')"/>Exists) == 'true'</xsl:attribute>
					<xsl:attribute name="Name">
						<xsl:value-of select="Name"/>
					</xsl:attribute>
					<xsl:attribute name="Application">
						<xsl:value-of select="parent::*/parent::*/Name"/>
					</xsl:attribute>
					<xsl:attribute name="RemoveInboundMaps">true</xsl:attribute>
					<xsl:attribute name="RemoveOutboundMaps">true</xsl:attribute>
					<xsl:if test="SendPipeline != 'Microsoft.BizTalk.DefaultPipelines.PassThruTransmit' and SendPipeline != 'Microsoft.BizTalk.DefaultPipelines.XMLTransmit'">
						<xsl:attribute name="SendPipeline">Microsoft.BizTalk.DefaultPipelines.PassThruTransmit, Microsoft.BizTalk.DefaultPipelines, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35</xsl:attribute>
					</xsl:if>
					<xsl:if test="ReceivePipeline != 'Microsoft.BizTalk.DefaultPipelines.XMLReceive' and ReceivePipeline != 'Microsoft.BizTalk.DefaultPipelines.PassThruReceive'">
						<xsl:attribute name="ReceivePipeline">Microsoft.BizTalk.DefaultPipelines.PassThruReceive, Microsoft.BizTalk.DefaultPipelines, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35</xsl:attribute>
					</xsl:if>

				</xsl:element>
				<xsl:element name="Message" namespace="http://schemas.microsoft.com/developer/msbuild/2003">
					<xsl:attribute name="Text" xml:space="preserve">    <xsl:value-of select="Name"/> reset and stopped</xsl:attribute>
				</xsl:element>
				<xsl:text>
				
				</xsl:text>
			</xsl:if>

			<xsl:if test="$action='Configure'">
				<xsl:element name="BizTalk2006.SendPort.Configure" namespace="http://schemas.microsoft.com/developer/msbuild/2003">
					<xsl:attribute name="Condition"  xml:space="preserve">@(SendPort<xsl:value-of select="translate(Name, ' .', '')"/>Exists) == 'true'</xsl:attribute>
					<xsl:attribute name="Name">
						<xsl:value-of select="./Name"/>
					</xsl:attribute>
					<xsl:attribute name="Application">
						<xsl:value-of select="parent::*/parent::*/Name"/>
					</xsl:attribute>
					<xsl:attribute name="IsDynamic">
						<xsl:value-of select="./Dynamic"/>
					</xsl:attribute>
					<xsl:attribute name="IsTwoWay">
						<xsl:value-of select="TwoWay"/>
					</xsl:attribute>
					<xsl:attribute name="Priority">
						<xsl:value-of select="Priority"/>
					</xsl:attribute>
					<xsl:attribute name="TrackingTypes">
						<xsl:value-of select="translate(TrackingType, ' .', ',')"/>
					</xsl:attribute>
					<xsl:attribute name="Filter">
						<xsl:value-of select="Filter"/>
					</xsl:attribute>
					<xsl:attribute name="InboundMaps">
						<xsl:value-of select="InboundMaps/Transform/AssemblyQualifiedName"/>
					</xsl:attribute>
					<xsl:attribute name="OutboundMaps">
						<xsl:value-of select="OutboundMaps/Transform/AssemblyQualifiedName"/>
					</xsl:attribute>
					<xsl:if test="$sendPipeline!=''">
						<xsl:attribute name="SendPipeline">
							<xsl:value-of select="/BizTalkBaseObject/Pipelines/Pipeline[Name=$sendPipeline]/AssemblyName"/>
						</xsl:attribute>
					</xsl:if>
					<xsl:if test="$receivePipeline!=''">
						<xsl:attribute name="ReceivePipeline">
							<xsl:value-of select="/BizTalkBaseObject/Pipelines/Pipeline[Name=$receivePipeline]/AssemblyName"/>
						</xsl:attribute>
					</xsl:if>
					<xsl:attribute name="PrimaryTransportAddress">
						<xsl:value-of select="PrimaryTransport/Address"/>
					</xsl:attribute>
					<xsl:attribute name="PrimaryTransportName">
						<xsl:value-of select="PrimaryTransport/Type"/>
					</xsl:attribute>
					<xsl:attribute name="PrimaryTransportOrderedDelivery">
						<xsl:value-of select="PrimaryTransport/OrderedDelivery"/>
					</xsl:attribute>
					<xsl:attribute name="PrimaryTransportProtocolName">
						<xsl:value-of select="PrimaryTransport/Type"/>
					</xsl:attribute>
					<xsl:attribute name="PrimaryTransportRetryCount">
						<xsl:value-of select="PrimaryTransport/RetryCount"/>
					</xsl:attribute>
					<xsl:attribute name="PrimaryTransportRetryInterval">
						<xsl:value-of select="PrimaryTransport/RetryInterval"/>
					</xsl:attribute>
					<xsl:attribute name="PrimaryTransportServiceWindowEnabled">
						<xsl:value-of select="PrimaryTransport/ServiceWindow/Enabled"/>
					</xsl:attribute>
					<xsl:attribute name="PrimaryTransportServiceWindowStartTime">
						<xsl:value-of select="PrimaryTransport/ServiceWindow/StartTime"/>
					</xsl:attribute>
					<xsl:attribute name="PrimaryTransportServiceWindowEndTime">
						<xsl:value-of select="PrimaryTransport/ServiceWindow/EndTime"/>
					</xsl:attribute>
					<xsl:if test="PrimaryTransport/DataSpecified='true'">
						<xsl:attribute name="PrimaryTransportTransportData">
							<xsl:value-of select="PrimaryTransport/CustomData"/>
						</xsl:attribute>
					</xsl:if>

					<xsl:if test="SecondaryTransport">
						<xsl:attribute name="SecondaryTransportAddress">
							<xsl:value-of select="SecondaryTransport/Address"/>
						</xsl:attribute>
						<xsl:attribute name="SecondaryTransportName">
							<xsl:value-of select="SecondaryTransport/Type"/>
						</xsl:attribute>
						<xsl:attribute name="SecondaryTransportOrderedDelivery">
							<xsl:value-of select="SecondaryTransport/OrderedDelivery"/>
						</xsl:attribute>
						<xsl:attribute name="SecondaryTransportProtocolName">
							<xsl:value-of select="SecondaryTransport/Type"/>
						</xsl:attribute>
						<xsl:attribute name="SecondaryTransportRetryCount">
							<xsl:value-of select="SecondaryTransport/RetryCount"/>
						</xsl:attribute>
						<xsl:attribute name="SecondaryTransportRetryInterval">
							<xsl:value-of select="SecondaryTransport/RetryInterval"/>
						</xsl:attribute>
						<xsl:attribute name="SecondaryTransportServiceWindowEnabled">
							<xsl:value-of select="SecondaryTransport/ServiceWindow/Enabled"/>
						</xsl:attribute>
						<xsl:attribute name="SecondaryTransportServiceWindowStartTime">
							<xsl:value-of select="SecondaryTransport/ServiceWindow/StartTime"/>
						</xsl:attribute>
						<xsl:attribute name="SecondaryTransportServiceWindowEndTime">
							<xsl:value-of select="SecondaryTransport/ServiceWindow/EndTime"/>
						</xsl:attribute>
						<xsl:if test="SecondaryTransport/DataSpecified='true'">
							<xsl:attribute name="SecondaryTransportTransportData">
								<xsl:value-of select="SecondaryTransport/CustomData"/>
							</xsl:attribute>
						</xsl:if>
					</xsl:if>
					<xsl:attribute name="Server">
						<xsl:value-of select="/BizTalkBaseObject/Server"/>
					</xsl:attribute>
					<xsl:attribute name="Database">
						<xsl:value-of select="/BizTalkBaseObject/MgmtDatabaseName"/>
					</xsl:attribute>
				</xsl:element>
				<xsl:element name="BizTalk2006.SendPort.Start" namespace="http://schemas.microsoft.com/developer/msbuild/2003">
					<xsl:attribute name="Condition" xml:space="preserve">@(SendPort<xsl:value-of select="translate(Name, ' .', '')"/>Exists) == 'true'</xsl:attribute>
					<xsl:attribute name="Name">
						<xsl:value-of select="./Name"/>
					</xsl:attribute>
					<xsl:attribute name="Application">
						<xsl:value-of select="parent::*/parent::*/Name"/>
					</xsl:attribute>
				</xsl:element>
				<xsl:element name="Message" namespace="http://schemas.microsoft.com/developer/msbuild/2003">
					<xsl:attribute name="Text" xml:space="preserve">    <xsl:value-of select="./Name"/> reconfigured and started</xsl:attribute>
				</xsl:element>
				<xsl:text>
					
				</xsl:text>
			</xsl:if>

		</xsl:for-each>
	</xsl:template>

	<!-- Send Port Groups-->
	<xsl:template name="SendPortGroups">
		<xsl:param name="action"/>

		<xsl:for-each select="/BizTalkBaseObject/Applications/Application/SendPortGroups/SendPortGroup">
			<xsl:if test="$action='Deploy'">
				<xsl:element name="BizTalk2006.SendPortGroup.Create" namespace="http://schemas.microsoft.com/developer/msbuild/2003">
					<xsl:attribute name="Name">
						<xsl:value-of select="Name"/>
					</xsl:attribute>
					<xsl:attribute name="Application">
						<xsl:value-of select="parent::*/parent::*/Name"/>
					</xsl:attribute>
					<xsl:attribute name="Filter">
						<xsl:call-template name="xml-to-string">
							<xsl:with-param name="node-set" select="FilterGroups"/>
						</xsl:call-template>
					</xsl:attribute>
					<xsl:attribute name="SendPorts">
						<xsl:for-each select="SendPorts/SendPort"><xsl:value-of select="Name"/>;</xsl:for-each>
					</xsl:attribute>
				</xsl:element>
			</xsl:if>
		</xsl:for-each>
	</xsl:template>
	
	<!-- Receive Ports-->
	<xsl:template name="ReceivePort">
		<xsl:param name="action"/>

		<xsl:for-each select="/BizTalkBaseObject/Applications/Application/ReceivePorts/ReceivePort">
			<xsl:variable name="sendPipeline" select="SendPipeline" />
			<xsl:if test="$action='Deploy'">
				<xsl:element name="BizTalk2006.ReceivePort.Create" namespace="http://schemas.microsoft.com/developer/msbuild/2003">
					<xsl:attribute name="Name">
						<xsl:value-of select="Name"/>
					</xsl:attribute>
					<xsl:attribute name="Application">
						<xsl:value-of select="parent::*/parent::*/Name"/>
					</xsl:attribute>
					<xsl:attribute name="TwoWay">
						<xsl:value-of select="TwoWay"/>
					</xsl:attribute>
					<xsl:attribute name="TrackingTypes">
						<xsl:value-of select="translate(TrackingType, ' .', ',')"/>
					</xsl:attribute>
					<xsl:attribute name="AuthenticationType">
						<xsl:value-of select="AuthenticationType"/>
					</xsl:attribute>
					<xsl:if test="$sendPipeline!=''">
						<xsl:attribute name="SendPipeline">
							<xsl:value-of select="/BizTalkBaseObject/Pipelines/Pipeline[Name=$sendPipeline]/AssemblyName"/>
						</xsl:attribute>
					</xsl:if>
					<xsl:attribute name="InboundMaps">
						<xsl:value-of select="InboundMaps/Transform/AssemblyQualifiedName"/>
					</xsl:attribute>
					<xsl:attribute name="OutboundMaps">
						<xsl:value-of select="OutboundMaps/Transform/AssemblyQualifiedName"/>
					</xsl:attribute>
				</xsl:element>

				<xsl:for-each select="ReceiveLocations/ReceiveLocation">
					<xsl:variable name="receivePipeline" select="ReceivePipeline"/>
					<xsl:element name="BizTalk2006.ReceiveLocation.AddReceiveLocation" namespace="http://schemas.microsoft.com/developer/msbuild/2003">
						<xsl:attribute name="Name">
							<xsl:value-of select="Name"/>
						</xsl:attribute>
						<xsl:attribute name="Application">
							<xsl:value-of select="parent::*/parent::*/Name"/>
						</xsl:attribute>
						<xsl:attribute name ="Address">
							<xsl:value-of select="Address"/>
						</xsl:attribute>
						<xsl:attribute name="PublicAddress">
							<xsl:value-of select="PublicAddress"/>
						</xsl:attribute>
						<xsl:if test="ReceivePipeline!=''">
							<xsl:attribute name="ReceivePipeline">
								<xsl:value-of select="/BizTalkBaseObject/Pipelines/Pipeline[Name=$receivePipeline]/AssemblyName"/>
							</xsl:attribute>
						</xsl:if>
						<xsl:attribute name="ReceiveHandler">
							<xsl:value-of select="ReceiveHandler"/>
						</xsl:attribute>
						<xsl:attribute name="ReceivePort">
							<xsl:value-of select="../../Name"/>
						</xsl:attribute>
						<xsl:attribute name="TransportType">
							<xsl:value-of select="TransportProtocol"/>
						</xsl:attribute>
						<xsl:attribute name="TransportTypeData">
							<xsl:value-of select="CustomData"/>
						</xsl:attribute>
						<xsl:attribute name="StartDateEnabled">
							<xsl:value-of select="ServiceWindow/StartDateEnabled"/>
						</xsl:attribute>
						<xsl:attribute name="StartDate">
							<xsl:value-of select="ServiceWindow/StartTime"/>
						</xsl:attribute>
						<xsl:attribute name="EndDateEnabled">
							<xsl:value-of select="ServiceWindow/EndDateEnabled"/>
						</xsl:attribute>
						<xsl:attribute name="EndDate">
							<xsl:value-of select="ServiceWindow/EndTime"/>
						</xsl:attribute>
						<xsl:attribute name="ServiceWindowEnabled">
							<xsl:value-of select="ServiceWindow/Enabled"/>
						</xsl:attribute>
						<xsl:attribute name="StartTime">
							<xsl:value-of select="ServiceWindow/StartTime"/>
						</xsl:attribute>
						<xsl:attribute name="EndTime">
							<xsl:value-of select="ServiceWindow/EndTime"/>
						</xsl:attribute>
					</xsl:element>
				</xsl:for-each>
				<xsl:element name="Message" namespace="http://schemas.microsoft.com/developer/msbuild/2003">
					<xsl:attribute name="Text" xml:space="preserve">    <xsl:value-of select="Name"/> created</xsl:attribute>
				</xsl:element>
				<xsl:text>
					
				</xsl:text>
			</xsl:if>

			<xsl:if test="$action='Undeploy'">
				<xsl:element name="BizTalk2006.ReceivePort.Delete" namespace="http://schemas.microsoft.com/developer/msbuild/2003">
					<xsl:attribute name="Condition" xml:space="preserve">@(ReceivePort<xsl:value-of select="translate(Name, ' .', '')"/>Exists) == 'true'</xsl:attribute>
					<xsl:attribute name="Name">
						<xsl:value-of select="Name"/>
					</xsl:attribute>
					<xsl:attribute name="Application">
						<xsl:value-of select="parent::*/parent::*/Name"/>
					</xsl:attribute>
				</xsl:element>
				<xsl:element name="Message" namespace="http://schemas.microsoft.com/developer/msbuild/2003">
					<xsl:attribute name="Text" xml:space="preserve">    <xsl:value-of select="Name"/> removed</xsl:attribute>
				</xsl:element>
				<xsl:text>
					
				</xsl:text>
			</xsl:if>

			<xsl:if test="$action='PreUndeploy'">
				<xsl:element name="BizTalk2006.ReceivePort.Configure" namespace="http://schemas.microsoft.com/developer/msbuild/2003">
					<xsl:attribute name="Condition" xml:space="preserve">@(ReceivePort<xsl:value-of select="translate(Name, ' .', '')"/>Exists) == 'true'</xsl:attribute>
					<xsl:attribute name="Name">
						<xsl:value-of select="Name"/>
					</xsl:attribute>
					<xsl:attribute name="Application">
						<xsl:value-of select="parent::*/parent::*/Name"/>
					</xsl:attribute>
					<xsl:attribute name="RemoveInboundMaps">true</xsl:attribute>
					<xsl:attribute name="RemoveOutboundMaps">true</xsl:attribute>
				</xsl:element>

				<xsl:for-each select="ReceiveLocations/ReceiveLocation">
					<xsl:element name="BizTalk2006.ReceiveLocation.Configure" namespace="http://schemas.microsoft.com/developer/msbuild/2003">
						<xsl:attribute name="Condition" xml:space="preserve">@(ReceiveLocation<xsl:value-of select="translate(Name, ' .', '')"/>Exists) == 'true'</xsl:attribute>
						<xsl:attribute name="Name">
							<xsl:value-of select="Name"/>
						</xsl:attribute>
						<xsl:attribute name="Application">
							<xsl:value-of select="parent::*/parent::*/Name"/>
						</xsl:attribute>
						<xsl:attribute name="ReceivePort">
							<xsl:value-of select="../../Name"/>
						</xsl:attribute>
						<xsl:if test="ReceivePipeline != 'Microsoft.BizTalk.DefaultPipelines.XMLReceive' and ReceivePipeline != 'Microsoft.BizTalk.DefaultPipelines.PassThruReceive'">
							<xsl:attribute name="ReceivePipeline">Microsoft.BizTalk.DefaultPipelines.PassThruReceive, Microsoft.BizTalk.DefaultPipelines, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35</xsl:attribute>
						</xsl:if>
						<xsl:attribute name="ReceiveHandler">
							<xsl:value-of select="ReceiveHandler"/>
						</xsl:attribute>
						<xsl:attribute name="TransportType">
							<xsl:value-of select="TransportProtocol"/>
						</xsl:attribute>
						<xsl:attribute name="TransportTypeData">
							<xsl:value-of select="CustomData"/>
						</xsl:attribute>
					</xsl:element>
				</xsl:for-each>
				<xsl:element name="Message" namespace="http://schemas.microsoft.com/developer/msbuild/2003">
					<xsl:attribute name="Text" xml:space="preserve">    <xsl:value-of select="Name"/> reset</xsl:attribute>
				</xsl:element>
				<xsl:text>
					
				</xsl:text>
			</xsl:if>

			<xsl:if test="$action='Configure'">
				<xsl:element name="BizTalk2006.ReceivePort.Configure" namespace="http://schemas.microsoft.com/developer/msbuild/2003">
					<xsl:attribute name="Condition" xml:space="preserve">@(ReceivePort<xsl:value-of select="translate(Name, ' .', '')"/>Exists) == 'true'</xsl:attribute>
					<xsl:attribute name="Name">
						<xsl:value-of select="Name"/>
					</xsl:attribute>
					<xsl:attribute name="Application">
						<xsl:value-of select="parent::*/parent::*/Name"/>
					</xsl:attribute>
					<!--xsl:attribute name="TwoWay">
						<xsl:value-of select="TwoWay"/>
					</xsl:attribute-->
					<xsl:attribute name="TrackingTypes">
						<xsl:value-of select="translate(TrackingType, ' .', ',')"/>
					</xsl:attribute>
					<xsl:attribute name="AuthenticationType">
						<xsl:value-of select="AuthenticationType"/>
					</xsl:attribute>
					<xsl:if test="$sendPipeline!=''">
						<xsl:attribute name="SendPipeline">
							<xsl:value-of select="/BizTalkBaseObject/Pipelines/Pipeline[Name=$sendPipeline]/AssemblyName"/>
						</xsl:attribute>
					</xsl:if>
					<xsl:attribute name="InboundMaps">
						<xsl:value-of select="InboundMaps/Transform/AssemblyQualifiedName"/>
					</xsl:attribute>
					<xsl:attribute name="OutboundMaps">
						<xsl:value-of select="OutboundMaps/Transform/AssemblyQualifiedName"/>
					</xsl:attribute>
				</xsl:element>

				<xsl:for-each select="ReceiveLocations/ReceiveLocation">
					<xsl:variable name="receivePipeline" select="ReceivePipeline"/>
					<xsl:element name="BizTalk2006.ReceiveLocation.Configure" namespace="http://schemas.microsoft.com/developer/msbuild/2003">
						<xsl:attribute name="Condition" xml:space="preserve">@(ReceiveLocation<xsl:value-of select="translate(Name, ' .', '')"/>Exists) == 'true'</xsl:attribute>
						<xsl:attribute name="Name">
							<xsl:value-of select="Name"/>
						</xsl:attribute>
						<xsl:attribute name="Application">
							<xsl:value-of select="parent::*/parent::*/Name"/>
						</xsl:attribute>
						<xsl:attribute name ="Address">
							<xsl:value-of select="Address"/>
						</xsl:attribute>
						<xsl:attribute name="PublicAddress">
							<xsl:value-of select="PublicAddress"/>
						</xsl:attribute>
						<xsl:if test="ReceivePipeline!=''">
							<xsl:attribute name="ReceivePipeline">
								<xsl:value-of select="/BizTalkBaseObject/Pipelines/Pipeline[Name=$receivePipeline]/AssemblyName"/>
							</xsl:attribute>
						</xsl:if>
						<xsl:attribute name="ReceiveHandler">
							<xsl:value-of select="ReceiveHandler"/>
						</xsl:attribute>
						<xsl:attribute name="ReceivePort">
							<xsl:value-of select="../../Name"/>
						</xsl:attribute>
						<xsl:attribute name="TransportType">
							<xsl:value-of select="TransportProtocol"/>
						</xsl:attribute>
						<xsl:attribute name="TransportTypeData">
							<xsl:value-of select="CustomData"/>
						</xsl:attribute>
						<xsl:attribute name="StartDateEnabled">
							<xsl:value-of select="ServiceWindow/StartDateEnabled"/>
						</xsl:attribute>
						<xsl:attribute name="StartDate">
							<xsl:value-of select="ServiceWindow/StartTime"/>
						</xsl:attribute>
						<xsl:attribute name="EndDateEnabled">
							<xsl:value-of select="ServiceWindow/EndDateEnabled"/>
						</xsl:attribute>
						<xsl:attribute name="EndDate">
							<xsl:value-of select="ServiceWindow/EndTime"/>
						</xsl:attribute>
						<xsl:attribute name="ServiceWindowEnabled">
							<xsl:value-of select="ServiceWindow/Enabled"/>
						</xsl:attribute>
						<xsl:attribute name="StartTime">
							<xsl:value-of select="ServiceWindow/StartTime"/>
						</xsl:attribute>
						<xsl:attribute name="EndTime">
							<xsl:value-of select="ServiceWindow/EndTime"/>
						</xsl:attribute>
					</xsl:element>
				</xsl:for-each>
				<xsl:element name="Message" namespace="http://schemas.microsoft.com/developer/msbuild/2003">
					<xsl:attribute name="Text" xml:space="preserve">    <xsl:value-of select="Name"/> configured</xsl:attribute>
				</xsl:element>
				<xsl:text>
					
				</xsl:text>
			</xsl:if>
		</xsl:for-each>
	</xsl:template>

	<!-- Deploy Assemblies-->
	<xsl:template name="DeployAssemblies">
		<xsl:param name="action"/>
		<xsl:if test="$action='Deploy'">
			<xsl:for-each select="$assemblyDependencyList/child::*">
				<xsl:sort order="descending" select="./@sortOrder"/>
				<xsl:element name="BizTalk2006.Assembly.Deploy" namespace="http://schemas.microsoft.com/developer/msbuild/2003" xml:space="default">
					<xsl:attribute name="AssemblyPath"><xsl:value-of select="$assemblyRootFolder"/>\<xsl:value-of select="substring-before(DisplayName, ',')"/>.dll</xsl:attribute>
					<xsl:attribute name="InstallInGac">True</xsl:attribute>
					<xsl:attribute name="Application">
						<xsl:value-of select="Application"/>
					</xsl:attribute>
				</xsl:element>
				<xsl:element name="Message" namespace="http://schemas.microsoft.com/developer/msbuild/2003">
					<xsl:attribute name="Text" xml:space="preserve">    <xsl:value-of select="DisplayName"/> deployed</xsl:attribute>
				</xsl:element>
				<xsl:text>
					
				</xsl:text>
			</xsl:for-each>
		</xsl:if>
		<xsl:if test="$action='Undeploy'">
			<xsl:for-each select="$assemblyDependencyList/child::*">
				<xsl:sort order="ascending" select="./@sortOrder"/>
				<xsl:element name="BizTalk2006.Assembly.Undeploy" namespace="http://schemas.microsoft.com/developer/msbuild/2003">
					<xsl:attribute name="Condition" xml:space="preserve">@(Assembly<xsl:value-of select="translate(substring-before(DisplayName, ','), '.', '')"/>Exists) == 'true'</xsl:attribute>
					<xsl:attribute name="AssemblyPath"><xsl:value-of select="$assemblyRootFolder"/>\<xsl:value-of select="substring-before(DisplayName, ',')"/>.dll</xsl:attribute>
					<xsl:attribute name="UninstallFromGac">True</xsl:attribute>
					<xsl:attribute name="Application">
						<xsl:value-of select="Application"/>
					</xsl:attribute>
				</xsl:element>
				<xsl:element name="Message" namespace="http://schemas.microsoft.com/developer/msbuild/2003">
					<xsl:attribute name="Text" xml:space="preserve">    <xsl:value-of select="DisplayName"/> undeployed</xsl:attribute>
				</xsl:element>
				<xsl:text>
					
				</xsl:text>
			</xsl:for-each>
		</xsl:if>
	</xsl:template>

	<!-- Orchestrations-->
	<xsl:template name="Orchestrations">
		<xsl:param name="action"/>
		<xsl:if test="$action='Deploy'">
			<xsl:for-each select="$orchestrationDependencyList/child::*">
				<xsl:sort order="descending" select="./@sortOrder" />

				<xsl:element name="BizTalk2006.Orchestration.Bind" namespace="http://schemas.microsoft.com/developer/msbuild/2003">
					<xsl:attribute name="Name">
						<xsl:value-of select="Name"/>
					</xsl:attribute>
					<xsl:attribute name="Application">
						<xsl:value-of select="Application"/>
					</xsl:attribute>
					<xsl:attribute name="AssemblyName">
						<xsl:value-of select="ParentAssembly/Name"/>
					</xsl:attribute>
					<xsl:attribute name="HostName">
						<xsl:value-of select="HostName"/>
					</xsl:attribute>
					<xsl:attribute name="OrchestrationPorts" xml:space="preserve">@(<xsl:value-of select="translate(Name, ' .', '')"/>Ports)</xsl:attribute>
				</xsl:element>
				<xsl:element name="BizTalk2006.Orchestration.Enlist" namespace="http://schemas.microsoft.com/developer/msbuild/2003">
					<xsl:attribute name="Name">
						<xsl:value-of select="Name"/>
					</xsl:attribute>
					<xsl:attribute name="Application">
						<xsl:value-of select="Application"/>
					</xsl:attribute>
					<xsl:attribute name="AssemblyName">
						<xsl:value-of select="ParentAssembly/Name"/>
					</xsl:attribute>
				</xsl:element>
				<xsl:element name="BizTalk2006.Orchestration.Start" namespace="http://schemas.microsoft.com/developer/msbuild/2003">
					<xsl:attribute name="Name">
						<xsl:value-of select="Name"/>
					</xsl:attribute>
					<xsl:attribute name="Application">
						<xsl:value-of select="Application"/>
					</xsl:attribute>
					<xsl:attribute name="AssemblyName">
						<xsl:value-of select="ParentAssembly/Name"/>
					</xsl:attribute>
				</xsl:element>
				<xsl:element name="Message" namespace="http://schemas.microsoft.com/developer/msbuild/2003">
					<xsl:attribute name="Text" xml:space="preserve">    <xsl:value-of select="Name"/> Bound, Enlisted and Started</xsl:attribute>
				</xsl:element>
				<xsl:text>
					
				</xsl:text>
			</xsl:for-each>
		</xsl:if>
		<xsl:if test="$action='Undeploy'">
			<xsl:for-each select="$orchestrationDependencyList/child::*">
				<xsl:sort order="ascending" select="./@sortOrder" />
				<xsl:element name="BizTalk2006.Orchestration.UnEnlist" namespace="http://schemas.microsoft.com/developer/msbuild/2003">
					<xsl:attribute name="Condition" xml:space="preserve">@(Orchestration<xsl:value-of select="translate(Name, ' .', '')"/>Exists) == 'true'</xsl:attribute>
					<xsl:attribute name="Name">
						<xsl:value-of select="Name"/>
					</xsl:attribute>
					<xsl:attribute name="Application">
						<xsl:value-of select="Application"/>
					</xsl:attribute>
					<xsl:attribute name="AssemblyName">
						<xsl:value-of select="ParentAssembly/Name"/>
					</xsl:attribute>
					<xsl:attribute name="TerminateExisting">true</xsl:attribute>
				</xsl:element>
				<xsl:element name="BizTalk2006.Orchestration.TerminateInstances" namespace="http://schemas.microsoft.com/developer/msbuild/2003">
					<xsl:attribute name="Condition" xml:space="preserve">@(Orchestration<xsl:value-of select="translate(Name, ' .', '')"/>Exists) == 'true'</xsl:attribute>
					<xsl:attribute name="Name">
						<xsl:value-of select="Name"/>
					</xsl:attribute>
					<xsl:attribute name="Application">
						<xsl:value-of select="Application"/>
					</xsl:attribute>
					<xsl:attribute name="AssemblyName">
						<xsl:value-of select="ParentAssembly/Name"/>
					</xsl:attribute>
				</xsl:element>
				<xsl:element name="BizTalk2006.Orchestration.Unbind" namespace="http://schemas.microsoft.com/developer/msbuild/2003">
					<xsl:attribute name="Condition" xml:space="preserve">@(Orchestration<xsl:value-of select="translate(Name, ' .', '')"/>Exists) == 'true'</xsl:attribute>
					<xsl:attribute name="Name">
						<xsl:value-of select="Name"/>
					</xsl:attribute>
					<xsl:attribute name="Application">
						<xsl:value-of select="Application"/>
					</xsl:attribute>
					<xsl:attribute name="AssemblyName">
						<xsl:value-of select="ParentAssembly/Name"/>
					</xsl:attribute>
				</xsl:element>
				<xsl:element name="Message" namespace="http://schemas.microsoft.com/developer/msbuild/2003">
					<xsl:attribute name="Text" xml:space="preserve">    <xsl:value-of select="Name"/> Stopped, Unenlisted, Running instances terminated and Unbound</xsl:attribute>
				</xsl:element>
				<xsl:text>
					
				</xsl:text>
			</xsl:for-each>
		</xsl:if>
	</xsl:template>

	<!-- Existance checks-->
	<xsl:template name="Exists">
		<xsl:for-each select="$applicationDependencyList/child::*">
			<xsl:element name="BizTalk2006.Application.Exists" namespace="http://schemas.microsoft.com/developer/msbuild/2003">
				<xsl:attribute name="Application">
					<xsl:value-of select="Name"/>
				</xsl:attribute>
				<xsl:element name="Output" namespace="http://schemas.microsoft.com/developer/msbuild/2003">
					<xsl:attribute name="ItemName">Application<xsl:value-of select="translate(Name, ' .', '')"/>Exists</xsl:attribute>
					<xsl:attribute name="TaskParameter">DoesExist</xsl:attribute>
				</xsl:element>
			</xsl:element>
		</xsl:for-each>
		<xsl:for-each select="$orchestrationDependencyList/child::*">
			<xsl:element name="BizTalk2006.Orchestration.Exists" namespace="http://schemas.microsoft.com/developer/msbuild/2003">
				<xsl:attribute name="Name">
					<xsl:value-of select="Name"/>
				</xsl:attribute>
				<xsl:attribute name="Application">
					<xsl:value-of select="Application"/>
				</xsl:attribute>
				<xsl:attribute name="AssemblyName">
					<xsl:value-of select="ParentAssembly/Name"/>
				</xsl:attribute>
				<xsl:element name="Output" namespace="http://schemas.microsoft.com/developer/msbuild/2003">
					<xsl:attribute name="ItemName" xml:space="preserve">Orchestration<xsl:value-of select="translate(Name, ' .', '')"/>Exists</xsl:attribute>
					<xsl:attribute name="TaskParameter">OrchestrationExists</xsl:attribute>
				</xsl:element>
			</xsl:element>
		</xsl:for-each>

		<xsl:for-each select="/BizTalkBaseObject/Applications/Application/DeployedAssemblies/Assembly">
			<xsl:element name="BizTalk2006.Assembly.Exists" namespace="http://schemas.microsoft.com/developer/msbuild/2003">
				<xsl:attribute name="DisplayName">
					<xsl:value-of select="DisplayName"/>
				</xsl:attribute>
				<xsl:attribute name="Application">
					<xsl:value-of select="parent::*/parent::*/Name"/>
				</xsl:attribute>
				<xsl:element name="Output" namespace="http://schemas.microsoft.com/developer/msbuild/2003">
					<!-- If the assembly name has dots in it, this will fail as dots are not allowed -->
					<xsl:attribute name="ItemName" xml:space="preserve">Assembly<xsl:value-of select="translate(substring-before(DisplayName, ','), '.', '')"/>Exists</xsl:attribute>
					<xsl:attribute name="TaskParameter">DoesExist</xsl:attribute>
				</xsl:element>
			</xsl:element>
		</xsl:for-each>

		<xsl:for-each select="/BizTalkBaseObject/Applications/Application/ReceivePorts/ReceivePort">
			<xsl:element name="BizTalk2006.ReceivePort.Exists" namespace="http://schemas.microsoft.com/developer/msbuild/2003">
				<xsl:attribute name="Name">
					<xsl:value-of select="Name"/>
				</xsl:attribute>
				<xsl:attribute name="Application">
					<xsl:value-of select="parent::*/parent::*/Name"/>
				</xsl:attribute>
				<xsl:element name="Output" namespace="http://schemas.microsoft.com/developer/msbuild/2003">
					<xsl:attribute name="ItemName" xml:space="preserve">ReceivePort<xsl:value-of select="translate(Name, ' .', '')"/>Exists</xsl:attribute>
					<xsl:attribute name="TaskParameter">ReceivePortExists</xsl:attribute>
				</xsl:element>
			</xsl:element>

			<xsl:for-each select="ReceiveLocations/ReceiveLocation">
				<xsl:element name="BizTalk2006.ReceiveLocation.Exists" namespace="http://schemas.microsoft.com/developer/msbuild/2003">
					<xsl:attribute name="Name">
						<xsl:value-of select="Name"/>
					</xsl:attribute>
					<xsl:attribute name="Application">
						<xsl:value-of select="../../../../Name"/>
					</xsl:attribute>
					<xsl:attribute name="ReceivePort">
						<xsl:value-of select="../../Name"/>
					</xsl:attribute>
					<xsl:element name="Output" namespace="http://schemas.microsoft.com/developer/msbuild/2003">
						<xsl:attribute name="ItemName" xml:space="preserve">ReceiveLocation<xsl:value-of select="translate(Name, ' .', '')"/>Exists</xsl:attribute>
						<xsl:attribute name="TaskParameter">ReceiveLocationExists</xsl:attribute>
					</xsl:element>
				</xsl:element>
			</xsl:for-each>
		</xsl:for-each>

		<xsl:for-each select="/BizTalkBaseObject/Applications/Application/SendPorts/SendPort">
			<xsl:element name="BizTalk2006.SendPort.Exists" namespace="http://schemas.microsoft.com/developer/msbuild/2003">
				<xsl:attribute name="Name">
					<xsl:value-of select="Name"/>
				</xsl:attribute>
				<xsl:attribute name="Application">
					<xsl:value-of select="../../Name"/>
				</xsl:attribute>
				<xsl:element name="Output" namespace="http://schemas.microsoft.com/developer/msbuild/2003">
					<xsl:attribute name="ItemName" xml:space="preserve">SendPort<xsl:value-of select="translate(Name, ' .', '')"/>Exists</xsl:attribute>
					<xsl:attribute name="TaskParameter">SendPortExists</xsl:attribute>
				</xsl:element>
			</xsl:element>
		</xsl:for-each>

		<xsl:variable name="hostlist" select="/BizTalkBaseObject/Hosts/Host"/>
		<xsl:for-each select="$hostlist">
			<xsl:element name="BizTalk2006.Host.Exists"  namespace="http://schemas.microsoft.com/developer/msbuild/2003">
				<xsl:attribute name="Name">
					<xsl:value-of select="Name"/>
				</xsl:attribute>
				<xsl:element name="Output" namespace="http://schemas.microsoft.com/developer/msbuild/2003">
					<xsl:attribute name="ItemName" xml:space="preserve">Host<xsl:value-of select="translate(Name, ' .', '')"/>Exists</xsl:attribute>
					<xsl:attribute name="TaskParameter">HostExists</xsl:attribute>
				</xsl:element>
			</xsl:element>

		</xsl:for-each>


	</xsl:template>

	<!-- Hosts-->
	<xsl:template name="Hosts">
		<xsl:variable name="hostlist" select="/BizTalkBaseObject/Hosts/Host"/>
		
		<xsl:for-each select="$hostlist">
			<xsl:element name="BizTalk2006.Host.Stop"  namespace="http://schemas.microsoft.com/developer/msbuild/2003">
				<xsl:attribute name="Condition" xml:space="preserve">@(Host<xsl:value-of select="translate(., ' .', '')"/>Exists) == 'true'</xsl:attribute>
				<xsl:attribute name="Name">
					<xsl:value-of select="."/>
				</xsl:attribute>
			</xsl:element>
			<xsl:element name="Message" namespace="http://schemas.microsoft.com/developer/msbuild/2003">
				<xsl:attribute name="Text" xml:space="preserve">    Host <xsl:value-of select="."/> Stopped</xsl:attribute>
			</xsl:element>
			<xsl:element name="BizTalk2006.Host.Start"  namespace="http://schemas.microsoft.com/developer/msbuild/2003">
				<xsl:attribute name="Condition" xml:space="preserve">@(Host<xsl:value-of select="translate(., ' .', '')"/>Exists) == 'true'</xsl:attribute>
				<xsl:attribute name="Name">
					<xsl:value-of select="."/>
				</xsl:attribute>
			</xsl:element>
			<xsl:element name="Message" namespace="http://schemas.microsoft.com/developer/msbuild/2003">
				<xsl:attribute name="Text" xml:space="preserve">    Host <xsl:value-of select="."/> Started</xsl:attribute>
			</xsl:element>
		</xsl:for-each>
	</xsl:template>
</xsl:stylesheet>
